#include "spdlogpacket.h"  // 替换为实际头文件名
#include <iostream>
#include <thread>
#include <vector>
using namespace bite;
void test_sync_logger() {
    try {
        bite::init_logger("sync_logger", "logs/sync_test.log", spdlog::level::debug);
        
        // 基础日志测试
        DBG("同步调试信息");
        INF("同步普通信息");
        WRN("同步警告信息");
        ERR("同步错误信息");
        
        // 格式验证测试
        DBG("带参数: {}", 123);
        INF("多参数: {}, {:.2f}", "test", 3.14159);
        
        // 文件日志测试
        auto file_logger = spdlog::basic_logger_mt<spdlog::async_factory>("file_test", "logs/file_test.log");
        file_logger->info("异步文件日志测试 {}", 456);
        
    } catch (const spdlog::spdlog_ex& ex) {
        std::cout << "日志初始化失败: " << ex.what() << std::endl;
    }
}

void test_async_logger() {
    try {
        bite::init_logger("async_logger", "logs/async_test.log", spdlog::level::debug);
        
        // 异步日志压力测试
        std::vector<std::thread> threads;
        for (int i = 0; i < 10; ++i) {
            threads.emplace_back([&](){
                for (int j = 0; j < 100; ++j) {
                    ERR("异步错误测试[线程{}-{}]", i, j);
                    WRN("异步警告测试[线程{}-{}]", i, j);
                }
            });
        }
        
        for (auto& t : threads) t.join();
        
    } catch (const spdlog::spdlog_ex& ex) {
        std::cout << "异步日志初始化失败: " << ex.what() << std::endl;
    }
}

void test_multithread() {
    try {
        bite::init_logger("mt_logger", "logs/mt_test.log", spdlog::level::debug);
        
        // 多线程日志测试
        std::vector<std::thread> threads;
        for (int i = 0; i < 4; ++i) {
            threads.emplace_back([&](){
                for (int j = 0; j < 50; ++j) {
                    INF("多线程信息[线程{}-{}]", i, j);
                    DBG("多线程调试[线程{}-{}]", i, j);
                }
            });
        }
        
        for (auto& t : threads) t.join();
        
    } catch (const spdlog::spdlog_ex& ex) {
        std::cerr << "多线程日志失败: " << ex.what() << std::endl;
    }
}

int main() {
    // 测试同步日志
    test_sync_logger();
    
    // 测试异步日志
    test_async_logger();
    
    // 测试多线程日志
    test_multithread();
    
    // 确保所有日志被刷新
    spdlog::drop_all();
    
    return 0;
}